package com.ruoyi.web.controller.warning;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warning.domain.entity.AlertRules;
import com.ruoyi.warning.domain.query.AlertRulesQuery;
import com.ruoyi.warning.service.IAlertRulesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/alertRules")
@Api(tags = "告警规则", description = "用于处理告警规则相关操作的控制器")
public class AlertRulesController {
    @Resource
    private IAlertRulesService alertRulesService;
    @ApiOperation("分页")
    @Log(title = "查询告警规则", businessType = BusinessType.SELECT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/page")
    public R<TableDataInfo> page(AlertRulesQuery query)
    {
        return R.ok(alertRulesService.getPage(query));
    }

    @ApiOperation("修改监控状态")
    @Log(title = "修改监控状态", businessType = BusinessType.UPDATE)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/updateDisable/{id}")
    public R updateDisable(@PathVariable String id)
    {
        AlertRules alertRules = alertRulesService.getById(id);
        alertRules.setDisabled(!alertRules.getDisabled());
        alertRulesService.updateById(alertRules);
        return R.ok();
    }
}
